<template>
  <view class="root">
    <view class="content" v-show="!visibleCamera">
      <uni-forms ref="form" :model="form" validateTrigger="blur" :border="true" err-show-type="toast"
        label-width="130px">
        <view class="title-require-style">居住信息(必填)</view>
        <view class="content-inner-wrapper content-inner-wrapper-live-info">
          <uni-forms-item label="标准地址" name="addressDetail" required v-if="['edit'].includes(options.type)">
            <view class="form-content-item" @click="">
              <view :class="form.addressDetail ? 'long-select-value' : 'long-select-value-empty'">
                {{form.addressDetail ? form.addressDetail : '请选择'}}
              </view>
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
          <!-- 新增 -->
          <uni-forms-item label="标准地址" name="addressDetail" required v-else>
            <view class="form-content-item" @click="handleAddressClick">
              <!-- <uni-easyinput type="text" v-model="form.addressDetail" disabled disableColor="#ffffff"
                :inputBorder="false" placeholder="请选择" :clearable="true" /> -->
              <view :class="form.addressDetail ? 'long-select-value' : 'long-select-value-empty'">
                {{form.addressDetail ? form.addressDetail : '请选择'}}
              </view>
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
          <uni-forms-item label="与房主关系" name="fTgryfzgx" required key="fTgryfzgx">
            <view class="form-content-item" @click="hadleShowPicker('homeowner_relationship', 'fTgryfzgx')">
              <uni-easyinput type="text" v-model="form.fTgryfzgx_text" disabled disableColor="#ffffff"
                :inputBorder="false" placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
        </view>
        <view class="title-require-style" v-if="['add', 'edit'].includes(options.type)">身份信息</view>
        <view class="content-inner-wrapper identity-form-wrapper" v-if="['add', 'edit'].includes(options.type)">
          <uni-forms-item label="国籍" name="nationality" required>
            <view class="form-content-item" @click="hadleShowPicker('nationality', 'nationality')">
              <uni-easyinput type="text" :disabled=" true  " v-model="form.nationality_text" disabled
                disableColor="#ffffff" :inputBorder="false" placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
          <uni-forms-item label="证件类型" name="idType" required>
            <view class="form-content-item" @click="hadleShowPicker('certificate_type', 'idType')">
              <uni-easyinput type="text" v-model="form.idType_text" disabled disableColor="#ffffff" :inputBorder="false"
                placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0" v-if="!currentOwner.nation"></uni-icons>
            </view>
          </uni-forms-item>

          <uni-forms-item label="证件号码" name="fGmsfhm" required>
            <view class="form-content-item">
              <uni-easyinput :type="form.idType == 10 ? 'idcard' : 'text'" :maxlength="18"
                :disabled="currentOwner.idCard ? true : false" v-model="form.fGmsfhm" :inputBorder="false"
                placeholder="请填写" :clearable="true" @blur="handleIdCardChange" />
              <u-icon v-if="form.idType == 10" slot="right" size="21" name="scan" color="#2488F5"
                @click="handleCamera"></u-icon>
            </view>
          </uni-forms-item>
          <uni-forms-item label="姓名" name="fXm" required>
            <view class="form-content-item" :class="form.fXm ? '' : 'input-item'">
              <uni-easyinput type="text" :disabled="currentOwner.userName ? true : false" v-model="form.fXm"
                :inputBorder="false" placeholder="请填写" :clearable="true" />
            </view>
          </uni-forms-item>
          <uni-forms-item label="出生日期" name="fCsrq" required>
            <view class="form-content-item" @click="handleShowDatetimePicker('fCsrq')">
              <uni-easyinput type="text" v-model="form.fCsrq" disabled disableColor="#ffffff" :inputBorder="false"
                placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
          <uni-forms-item label="性别" name="fXbdm" required>
            <view class="form-content-item" @click="hadleShowPicker('sex_type', 'fXbdm')">
              <uni-easyinput type="text" v-model="form.fXbdm_text" disabled disableColor="#ffffff" :inputBorder="false"
                placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0"></uni-icons>
            </view>
          </uni-forms-item>
          <uni-forms-item label="民族" name="fMzdm" required v-if="form.idType == 10">
            <view class="form-content-item" @click="hadleShowPicker('nation', 'fMzdm')">
              <uni-easyinput type="text" :disabled="currentOwner.nation ? true : false" v-model="form.fMzdm_text"
                disabled disableColor="#ffffff" :inputBorder="false" placeholder="请选择" :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0" v-if="!currentOwner.nation"></uni-icons>
            </view>
          </uni-forms-item>
          <!-- <uni-forms-item label="户籍地址" name="fHjdzQhnxxdz" required>
            <view class="form-content-item" :class="form.fHjdzQhnxxdz ? '' : 'input-item'">
              <view :class="form.addressDetail ? 'long-select-value' : 'long-select-value-empty'"
                v-if="currentOwner.residenceAddress">
                {{form.addressDetail ? form.addressDetail : '请选择'}}
              </view>
              <uni-easyinput type="text" v-else v-model="form.fHjdzQhnxxdz" disableColor="#ffffff" :inputBorder="false"
                placeholder="请填写" :clearable="true" />
            </view>
          </uni-forms-item>
          <uni-forms-item label="户籍地所属区县" name="fHjdzSsxqdm" required>
            <view class="form-content-item" @click="handleClickCityPicker">
              <uni-easyinput type="text" :disabled="currentOwner.hjssxqbm ? true : false"
                v-model="form.fHjdzSsxqdm_text" disabled disableColor="#ffffff" :inputBorder="false" placeholder="请选择"
                :clearable="true" />
              <uni-icons type="right" size="21" color="#C2C0C0" v-if="!currentOwner.nation"></uni-icons>
            </view>
          </uni-forms-item>
          <view class="hint" style="font-size: 10px;color: #f56c6c;margin-top: -20rpx;padding-bottom: 10rpx;"
            v-if="areaList.length">
            户籍所属区县由系统自动匹配，如匹配不准确或未匹配到请务必手动修改!
          </view> -->
          <uni-forms-item label="联系电话" name="fLxdh">
            <view class="form-content-item" :class="form.fLxdh ? '' : 'input-item'">
              <uni-easyinput type="number" :maxlength="11" :disabled="currentOwner.phone ? true : false"
                v-model="form.fLxdh" :inputBorder="false" placeholder="请填写" :clearable="true" />
            </view>
          </uni-forms-item>
          <uni-forms-item label="人脸照片" name="fFaceUrl"> </uni-forms-item>
          <u-upload :fileList="form.fFaceUrl" @afterRead="afterReadFive" @delete="deletePhoto" name="fFaceUrl"
            :maxCount="1" :multiple="true" width="96" height="80">
            <image :src="baseImgUrl + 'upload-icon3.png'" style="width: 200rpx; height: 160rpx"></image>
          </u-upload>
        </view>
      </uni-forms>

      <view class="button-wrapper">
        <view class="cancel btn-item" @click="handleCancel">取消</view>
        <u-button class="custom-style" text="保存" @click="handleSubmit" :disabled="loading"
          :custom-style="customSubmitStyleHalf"></u-button>
      </view>

      <u-picker closeOnClickOverlay v-if="pickerShow" :show="pickerShow" :columns="pickerData" keyName="text"
        @confirm="onPickerConfirm" @cancel="pickerShow = false" @close="pickerShow = false"
        :defaultIndex="defaultIndex"></u-picker>
      <!-- <yy-city-picker :visible="cityPickerVisible" @confirm="onCityConfirm"
        @cancel="cityPickerVisible = false"></yy-city-picker> -->
      <yy-city-picker-all v-if="cityPickerVisible" :visible="cityPickerVisible" @confirm="onCityConfirm"
        @cancel="cityPickerVisible = false" :default-value="defaultCityCode"></yy-city-picker-all>

      <view style="position: relative;z-index: 100000;">
        <u-popup :show="showSelectOwner" @close="closeSelectOwner" @open="openSelectOwner" mode="center" round="10"
          closeable>
          <view class="select-owner-style" style="width: 500rpx;padding: 40px 15px 20px 15px;">
            <u-radio-group v-model="currentOwnerId" borderBottom iconPlacement="right" placement="column"
              @change="handleSelectOwnerChange">
              <u-radio :label="item.userName" :name="item.id" v-for="(item, index) in ownerList" :key="index"></u-radio>
            </u-radio-group>
          </view>
        </u-popup>
      </view>
    </view>
    <yy-photo-mask :visible.sync="visibleCamera" :baseImgUrl="baseImgUrl" :clientId="clientId"
      :clientSecret="clientSecret" @generateFilePath="onGenerateFilePath"
      @parsedSuccess="onParsedSuccess"></yy-photo-mask>
    <yy-watermark></yy-watermark>
    <lingfeng-timepicker ref="datetimePickerRef" type="date" :defaultData="defaultData" :minDate="minDate"
      :maxDate="maxDate" @change="timeChange"></lingfeng-timepicker>
  </view>
</template>

<script>
  import {
    addPersonInfo,
    getIdPersonInfo,
    selectHeadBybm,
    updatePersonInfo,
  } from "../api/api";
  import {
    postAction
  } from "../utils/request";
  import {
    findCompany,
    infoDetailSave
  } from "@/api/home";
  import moment from "@/utils/moment";
  import pickerMixin from "@/utils/picker-mixin";
  import _ from "@/utils/lodash.js";

  import {
    Toast,
    checkIDCard,
    getHeader,
    isLoading,
    navBack,
    parseJson,
    selectNation,
    uploadFile,
    customSubmitStyleHalf,
    setDefaultProvinceCode,
    parseIDCard,
  } from "@/utils/util";

  export default {
    mixins: [pickerMixin],
    data() {
      return {
        form: this.initForm(),
        baseImgUrl: this.$baseImgUrl,
        baseURL: this.$baseURL,
        clientId: this.$clientId,
        clientSecret: this.$clientSecret,
        visibleCamera: false,
        imgPrefix: uni.getStorageSync("imgPrefix"),
        rules: {
          addressDetail: {
            rules: [{
              required: true,
              errorMessage: "请选择标准地址！",
            }, ],
          },
          fTgryfzgx: {
            rules: [{
              required: true,
              errorMessage: "请选择与房主关系！",
            }, ],
          },
          nationality: {
            rules: [{
              required: true,
              errorMessage: "请选择国籍！",
            }, ],
          },
          idType: {
            rules: [{
              required: true,
              errorMessage: "请选择证件类型！",
            }, ],
          },
          fGmsfhm: {
            rules: [{
                required: true,
                errorMessage: "请填写证件号码！",
              },
              {
                validateFunction: (rule, value, data, callback) => {
                  // 是身份证的时候再进行身份证的格式校验
                  if (!checkIDCard(value) && this.form.idType == 10) {
                    callback("请输入正确的证件号码!");
                  }
                  return true;
                },
              },
            ],
          },
          fXm: {
            rules: [{
              required: true,
              errorMessage: "请填写姓名！",
            }, ],
          },
          fCsrq: {
            rules: [{
              required: true,
              errorMessage: "请选择出生日期！",
            }, ],
          },
          fXbdm: {
            rules: [{
              required: true,
              errorMessage: "请选择性别！",
            }, ],
          },
          fMzdm: {
            rules: [{
              required: true,
              errorMessage: "请选择民族！",
            }, ],
          },
          // fHjdzQhnxxdz: {
          //   rules: [{
          //     required: true,
          //     errorMessage: "请填写户籍地址！",
          //   }, ],
          // },
          // fHjdzSsxqdm: {
          //   rules: [{
          //     required: true,
          //     errorMessage: "请选择户籍地所属区县！",
          //   }, ],
          // },
          fLxdh: {
            rules: [{
                required: false,
                errorMessage: "请填写联系电话！",
              },
              {
                validateFunction: (rule, value, data, callback) => {
                  if (!this.$u.test.mobile(value)) {
                    callback("请输入正确的联系电话!");
                  }
                  return true;
                },
              },
            ],
          },
        },
        options: {},
        formDictMap: [
          "fFwlb",
          "fFwxz",
          "fFwlx",
          "fFwzt",
          "fIszdgz",
          "fFwyt",
          "fSftgrtg",
          "fTgryfzgx",
          // "fHjdzSsxqdm",
          "fMzdm",
          // "fHjdzQhnxxdz",
        ],
        isEmpty: false,
        addressInfo: {},
        dictMapping: {},
        cityPickerVisible: false,
        customSubmitStyleHalf,
        loading: false,
        // 选择房主
        showSelectOwner: false,
        currentOwnerId: '',
        currentOwner: {},
        ownerList: [],

        areaList: [],
        defaultCityCode: '',
        // 日期相关的
        defaultData: {
          startTime: moment(new Date()).format('YYYY-MM-DD')
        },
        minDate: {
          year: 1800,
          month: 1,
          date: 1
        },
        maxDate: {
          year: new Date().getFullYear(),
          month: new Date().getMonth() + 1,
          date: new Date().getDate()
        },
        datetimePickerRef: null
      };
    },
    watch: {},
    // 定义 actionType 'add' 'modify'
    // 其他参数放在 params 里面
    onLoad(options) {
      this.options = options;
      this.initDict();
      // 如果 id 则说明是编辑
      // 如果 id 则说明是编辑
      if (options.addressInfo) {
        this.addressInfo = JSON.parse(decodeURIComponent(options.addressInfo));
        this.form.fNames = this.addressInfo.bName;
        this.form.addressDetail = this.addressInfo.roomName;
        this.standardAddress = this.form.fNames + this.form.addressDetail;
      }

      // 如果 id 则说明是编辑
      if (options.fId) {
        uni.setNavigationBarTitle({
          title: "编辑实有人口",
        });
        let params = {
          fId: options.fId,
        };
        isLoading();
        getIdPersonInfo(params)
          .then((res) => {
            if (res.code == 200) {
              let form = _.pick(res.result, Object.keys(this.initForm()));
              form.fFaceUrl = form.fFaceUrl ? form.fFaceUrl
                .split()
                .filter((item) => item !== "")
                .map((item) => {
                  return {
                    url: this.imgPrefix + item,
                    halfPath: item,
                  };
                }) : []
              this.form = Object.assign({}, this.form, form);
              // this.defaultCityCode = res.result.fHjdzSsxqdm
              this.formDictMap.forEach((key) => {
                this.$set(this.form, `${key}_text`, res.result[`${key}Name`]);
              });
              // 男女和生日
              const {
                fCsrq,
                fXbdm
              } = res.result
              if (fCsrq) {
                this.$set(this.form, `fCsrq`, fCsrq)
              }
              if (fXbdm) {
                this.$set(this.form, `fXbdm_text`, fXbdm == 0 ? '女' : '男')
                this.$set(this.form, `fXbdm`, fXbdm)
              }
            }
          })
          .finally(() => {
            isLoading(false);
          });
      } else {
        uni.setNavigationBarTitle({
          title: "添加实有人口",
        });
      }
      uni.$on("select-standard-address", (data) => {
        const {
          fJlxxqmc,
          fDzbm,
          roomName,
          jzFDzbm,
          dyFDzbm,
          lcFDzbm,
          fzFDzbm,
          jlxFDzbm,
          buildType,
        } = data;
        const formFields = ['fNames', 'addressDetail', 'fSsjzwDzbm', 'fSsdyDzbm', 'fSslcDzbm',
          'fSsjzwdyfwDzbm', 'fSsjlxxqDzbm', 'buildType'
        ]
        let oldAddress = _.pick(this.form, formFields)
        // 从标准地址里面取出新的对象 和老的进行比较  并去除 假值
        let newAddress = _.pickBy(_.pick({
          fNames: fJlxxqmc,
          addressDetail: roomName,
          fSsjzwDzbm: jzFDzbm,
          fSsdyDzbm: dyFDzbm,
          fSslcDzbm: lcFDzbm,
          fSsjzwdyfwDzbm: fzFDzbm,
          fSsjlxxqDzbm: jlxFDzbm,
          buildType: buildType + ""
        }, formFields), (val, key) => !!val)

        if (!_.isEqual(oldAddress, newAddress)) {
          this.setStandardAddressInfo(data);
          // 并且清空与房主关系
          this.form.fTgryfzgx_text = ''
          this.form.fTgryfzgx = ''
        }
      });
    },
    onReady() {
      this.$refs.form.setRules(this.rules);
    },
    methods: {
      handleIdCardChange() {
        let params = {
          idCard: this.form.fGmsfhm,
          fDzbm: this.form.fSsjzwDzbm
        }
        // 根据最新的身份证信息计算出出生日期 和 性别 当证件类型为 身份证的时候
        if (this.form.idType == 10) {
          this.setBirthdayAdnSex(this.form.fGmsfhm)
          setDefaultProvinceCode.call(this, params, ({
            code,
            address
          }) => {
            this.defaultCityCode = code
            // this.$set(this.form, 'fHjdzSsxqdm_text', address)
            // this.$set(this.form, 'fHjdzSsxqdm', code)
          })
        }
      },
      initDict() {
        let allCode = uni.getStorageSync("allCode");
        Object.assign(this.dictMapping, allCode);
      },
      moment,
      setStandardAddressInfo(data) {
        const {
          fJlxxqmc,
          fDzbm,
          roomName,
          jzFDzbm,
          dyFDzbm,
          lcFDzbm,
          fzFDzbm,
          jlxFDzbm,
          buildType,
        } = data;
        if (fJlxxqmc) this.$set(this.form, "fNames", fJlxxqmc);
        if (roomName) this.$set(this.form, "addressDetail", roomName); // 房间的完整名字
        if (jzFDzbm) this.$set(this.form, "fSsjzwDzbm", jzFDzbm); // 建筑物
        if (dyFDzbm) this.$set(this.form, "fSsdyDzbm", dyFDzbm);
        if (lcFDzbm) this.$set(this.form, "fSslcDzbm", lcFDzbm);
        if (fzFDzbm) this.$set(this.form, "fSsjzwdyfwDzbm", fzFDzbm); // 房屋id
        if (jlxFDzbm) this.$set(this.form, "fSsjlxxqDzbm", jlxFDzbm);
        if (buildType !== undefined)
          this.$set(this.form, "buildType", buildType + "");
      },
      initForm() {
        return {
          addressDetail: "",
          fFwlb: "",
          fFwxz: "",
          fFwlx: "",
          fIszdgz: "",
          fFwyt: "",
          fFwjs: "",
          fFwmj: "",
          fFwcqh: "",
          fSftgrtg: "",
          fGmsfhm: "",
          fXm: "",
          fLxdh: "",
          fFaceUrl: [],
          fTgryfzgx: "",
          // 民族
          fMzdm: "",
          fMzdm_text: "",
          // fHjdzQhnxxdz: "", // 户籍地址
          // fHjdzSsxqdm: "", // 户籍编码
          // fHjdzSsxqdm_text: "",
          nationality: 'CHN',
          nationality_text: '中国',
          idType: '10',
          idType_text: '身份证',
          fCsrq: '',
          fXbdm: ''
        };
      },
      onTimeChange(e) {
        this.form.openingTime = e;
      },
      handleSubmit() {
        this.$refs.form
          .validate()
          .then(async (res) => {
            let params = {
              ...this.form,
              ...this.addressInfo,
              fFaceUrl: this.form.fFaceUrl.map((item) => item.halfPath).join(""),
            };
            // 判断民族不是身份证，则默认传递 ''
            if (params.idType != 10) {
              params.nation = ''
            }
            if (this.options.fId) {
              params.fId = this.options.fId;
              // 编辑
              this.loading = true;
              updatePersonInfo(params)
                .then((res) => {
                  if (res.code == 200) {
                    Toast("编辑成功！");
                    setTimeout(() => {
                      navBack();
                    }, 1000)
                  } else {
                    this.loading = false
                    Toast(res.message)
                  }
                })
                .catch(() => {
                  this.loading = false;
                });
            } else {
              this.loading = true;
              addPersonInfo(params)
                .then((res) => {
                  if (res.code == 200) {
                    Toast("添加成功！");
                    setTimeout(() => {
                      navBack();
                    }, 1000)
                  } else {
                    this.loading = false
                    Toast(res.message)
                  }
                })
                .catch(() => {
                  this.loading = false;
                });
            }
          })
          .catch((err) => {
            // 表单校验验失败，err 为具体错误信息
          });
      },
      handleCancel() {
        navBack();
      },
      onGenerateFilePath(fileurl) {
        this.uploadImage(fileurl, 44);
      },
      handleCamera() {
        this.visibleCamera = true;
      },
      uploadImage(fileurl, type) {
        uploadFile({
            url: "/web/sys/upload/upload_file",
            filePath: fileurl,
            name: "file",
            formData: {
              type,
            },
            success: (res) => {},
          })
          .then((res) => {
            let {
              fullPath,
              halfPath
            } = res.result;
            if (type == 44) {
              this.fileList = [];
              this.fileList.push({
                url: fullPath,
              });
              this.form.idCardImage = halfPath;
            }
          })
          .finally(() => {
            isLoading(false);
          });
      },
      onParsedSuccess(value) {
        const {
          domicileAddress,
          userName,
          idcard,
          nation
        } = value;
        this.$set(this.form, "fXm", userName);
        this.$set(this.form, "fGmsfhm", idcard);
        // this.$set(this.form, "fHjdzQhnxxdz", domicileAddress);
        this.handleIdCardChange()
        let nationOption = selectNation(this.dictMapping, nation);
        if (nationOption) {
          this.form.fMzdm = nationOption.value;
          this.form.fMzdm_text = nationOption.text;
        }
        this.visibleCamera = false;
      },
      handleAddressClick() {
        uni.navigateTo({
          url: "/actual_real_estate/selectStandardAddress",
        });
      },
      deletePhoto(event) {
        this.form[event.name].splice(event.index, 1);
      },
      afterReadFive(info) {
        const {
          file,
          name
        } = info;
        let promiseList = file.map((v) => {
          return uploadFile({
            url: "/web/sys/upload/upload_file",
            filePath: v.url,
            name: "file",
            formData: {
              type: 19,
            },
          });
        });
        isLoading();
        Promise.all(promiseList)
          .then((res) => {
            res.forEach((item) => {
              let result = item.result;
              this.form[name].push({
                url: result.fullPath,
                halfPath: result.halfPath,
              });
            });
          })
          .catch((err) => {})
          .finally(() => {
            isLoading(false);
          });
      },
      onCityConfirm(event) {
        // this.form.fHjdzSsxqdm_text = event.address;
        // this.form.fHjdzSsxqdm = event.code;
        this.cityPickerVisible = false;
      },
      openSelectOwner() {},
      closeSelectOwner() {
        this.currentOwnerId = ''
        this.showSelectOwner = false
      },
      handleSelectOwnerChange(n) {
        const currentOwner = this.ownerList.find((item) => item.id === n)
        if (currentOwner) {
          // 取出里面的值给 form 赋值
          this.setPersonInfo(currentOwner)
          // 选完之后关闭
          this.showSelectOwner = false
        }
      },
      setPersonInfo(currentOwner) {
        this.currentOwner = currentOwner
        const {
          idCard,
          userName,
          nation,
          nationName,
          hjssxqbmName,
          hjssxqbm, // 户籍省市区编码
          phone,
          residenceAddress // 户籍地址
        } = currentOwner
        this.form.fGmsfhm = idCard
        this.form.fXm = userName
        this.form.fMzdm = nation
        this.form.fMzdm_text = nationName
        // this.form.fHjdzQhnxxdz = residenceAddress
        // this.form.fHjdzSsxqdm = hjssxqbm
        // this.form.fHjdzSsxqdm_text = hjssxqbmName
        this.form.fLxdh = phone
        // 给生日和男女设置默认值
        if (this.form.idType == 10) {
          this.setBirthdayAdnSex(this.form.fGmsfhm)
        }
      },
      clearPersonInfo() {
        this.form.idCardImage = ''
        this.form.fGmsfhm = ''
        this.form.fXm = ''
        this.form.fMzdm = ''
        this.form.fMzdm_text = ''
        // this.form.fHjdzQhnxxdz = ''
        // this.form.fHjdzSsxqdm = ''
        // this.form.fHjdzSsxqdm_text = ''
        this.form.fLxdh = ''
        this.currentOwner = {}
      },
      onPickerConfirm(data, formName = 'form') {
        let {
          value,
          text
        } = data.value[0];
        this[formName][this.pickerWithFormKey] = value;
        this.$set(this[formName], `${this.pickerWithFormKey}_text`, text);
        // 判断如 与房主关系十 房屋本人，则调接口查询
        // 只在新增的时候执行这个逻辑
        if (['add'].includes(this.options.type) && this.pickerWithFormKey === 'fTgryfzgx') {
          // 改变了的话先清空值
          this.clearPersonInfo()
          // 如果选的是与房主关系，则调接口查询当前标准地址的 房主本人的信息
          if (value === '101') {
            // 改变之后先清空值
            let params = {
              buildType: this.form.buildType,
              // 0 房屋 1 建筑物
              id: this.form.buildType == 0 ? this.form.fSsjzwdyfwDzbm : this.form.fSsjzwDzbm
            }
            selectHeadBybm(params)
              .then((res) => {
                if (res.code == 200) {
                  const {
                    result
                  } = res
                  if (result) {
                    if (result.length == 1) {
                      // 给默认值
                      this.setPersonInfo(result[0])
                    } else if (result.length > 1) {
                      this.showSelectOwner = true
                      this.ownerList = result
                    }
                  }
                } else {
                  Toast(res.message)
                }
              })
          }
        }
        this.pickerShow = false;
      },
      hadleShowPicker(dictName, formKey, formName = 'form') {
        this.pickerWithFormKey = formKey;
        if (formKey === 'fTgryfzgx' && ['add'].includes(this.options.type)) {
          if (this.form.buildType === undefined) {
            Toast('请选择标准地址')
            return
          }
        }
        // 如果有房屋本人 并且选的是民族  不弹窗
        if (formKey === 'fMzdm') {
          if (this.currentOwner.nation) {
            return
          }
        }
        // 如果是
        this.pickerData[0] = this.dictMapping[dictName] || [];
        let index = this.pickerData[0].findIndex(item => item.value == this[formName][formKey])
        if (~index) {
          this.defaultIndex = [index]
        } else {
          this.defaultIndex = [0]
        }
        this.pickerShow = true;
      },
      handleClickCityPicker() {
        // 如果能拿到房主信息 的户籍，则不用 再选了
        if (this.currentOwner.hjssxqbm) {
          return
        }
        this.cityPickerVisible = true
      },
      handleShowDatetimePicker(type) {
        // 库里面能查到
        this.$refs.datetimePickerRef.show()
      },
      timeChange(val) {
        this.form.fCsrq = moment(val).format('YYYY-MM-DD')
      },
      setBirthdayAdnSex(idCard) {
        const {
          birthDate,
          gender
        } = parseIDCard(idCard)
        this.form.fCsrq = moment(birthDate).format("YYYY-MM-DD")
        this.form.fXbdm = gender == '男' ? '1' : '2'
        this.form.fXbdm_text = gender
      }
    },
  };
</script>

<style>
  page {
    background: #f9f9f9;
    box-sizing: border-box;
  }
</style>

<style lang="scss" scoped>
  @import "../styles/uni-form.scss";
  @import "../styles/submit-button.scss";

  .root {
    .content {
      padding-bottom: 40rpx;

      .content-inner-wrapper {
        padding: 0 16rpx;
        border-radius: 16rpx 16rpx 16rpx 16rpx;
        background: #fff;
        margin-bottom: 10rpx;
      }
    }

    /deep/.uni-forms {
      margin-bottom: 130rpx;
    }

    .identity-form-wrapper,
    .content-inner-wrapper-live-info {
      /deep/.uni-forms-item:nth-child(1) {
        border: 0 !important;
      }
    }

    .title-require-style {
      font-weight: 500;
      font-size: 26rpx;
      color: #999999;
      height: 100rpx;
      display: flex;
      align-items: center;
    }

    .select-owner-style {
      /deep/.u-radio-group {
        max-height: 500rpx;
        overflow: auto;
      }

      /deep/.u-radio {
        padding-top: 8px;
      }
    }
  }
</style>